local extension=Package("unostart")
extension.extensionName="jbs2"
local U = require "packages/utility/utility"
local T = require "packages/jbs/record/Theorem"
extension.game_modes_whitelist={"jbsuno_mode"}

Fk:loadTranslationTable{
    ["unostart"]="uno-启航",
   
    
}



local daqiao=T.creategenandtanslatene({extension,"poke__daqiao","wu",3,3,General.Female},{"大乔","绝色"})
daqiao:addSkill("guose")


local zhugeliang=T.creategenandtanslatene({extension,"poke__zhugeliang","shu"},{"诸葛亮","丞相"})
local luxun=T.creategenandtanslatene({extension,"poke__luxun","wu"},{"陆逊","男娘"})
local caocao=T.creategenandtanslatene({extension,"poke__caocao","wei"},{"曹操","男娘"})
local liubei=T.creategenandtanslatene({extension,"poke__liubei","shu"},{"刘备","男娘"})
local zhangfei=T.creategenandtanslatene({extension,"poke__zhangfei","shu"},{"张飞","男娘"})
--local zhaoyun=T.creategenandtanslatene({extension,"poke__zhaoyun","shu"},{"赵云","男娘"})
local machao=T.creategenandtanslatene({extension,"poke__machao","shu"},{"马超","男娘"})
--local zhangliao=T.creategenandtanslatene({extension,"poke__zhangliao","wei"},{"张辽","男娘"})
local guojia=T.creategenandtanslatene({extension,"poke__guojia","wei"},{"郭嘉","男娘"})
local simayi=T.creategenandtanslatene({extension,"poke__simayi","wei"},{"司马懿","男娘"})
local xuchu=T.creategenandtanslatene({extension,"poke__xuchu","wei"},{"许褚","男娘"})
local sunquan=T.creategenandtanslatene({extension,"poke__sunquan","wu"},{"孙权","男娘"})
local lvmeng=T.creategenandtanslatene({extension,"poke__lvmeng","wu"},{"吕蒙","男娘"})
local ganning=T.creategenandtanslatene({extension,"poke__ganning","wu"},{"甘宁","男娘"})
local zhouyu=T.creategenandtanslatene({extension,"poke__zhouyu","wu"},{"周瑜","男娘"})
local diaochan=T.creategenandtanslatene({extension,"poke__diaochan","qun",3,3,General.Female},{"貂蝉","绝色"})
local zhurong=T.creategenandtanslatene({extension,"poke__zhurong","shu",3,3,General.Female},{"祝融","绝色"})
local wolong=T.creategenandtanslatene({extension,"poke__wolong","shu"},{"卧龙诸葛","男娘"})
guojia:addSkill("hongyan")
simayi:addSkill("guicai")
ganning:addSkill("qixi")

local qianxun = fk.CreateViewAsSkill{
    name = "poke__qianxun",
    anim_type = "control",
    pattern = "ex_nihilo",
    card_filter = function(self, to_select, selected)
      return #selected == 0 and Fk:getCardById(to_select).number<= Self:getHandcardNum() 
    end,
    view_as = function(self, cards)
      if #cards ~= 1 then
        return nil
      end
      local c = Fk:cloneCard("ex_nihilo")
      c.skillName = self.name
      c:addSubcard(cards[1])
      return c
    end,
  }

local kanpo = fk.CreateViewAsSkill{
    name = "poke__kanpo",
    anim_type = "control",
    pattern = ".",
    card_filter = function(self, to_select, selected)
      return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
      and #table.filter(Fk:currentRoom().alive_players ,function (p) return p:getHandcardNum() >=Self:getHandcardNum() end)==1
    end,
    view_as = function(self, cards)
      if #cards ~= 1 then return end
      local card = Fk:cloneCard("nullification")
      card.skillName = self.name
      card:addSubcard(cards[1])
      return card
    end,
  }
  
local jianxiong=fk.CreateTriggerSkill{
  name = "poke__jianxiong",
  anim_type = "offensive",
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player:getLastAlive() and player:usedSkillTimes(self.name, Player.HistoryGame) <= 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player,data.card,false, fk.ReasonJustMove)
  end,
}

local rende=fk.CreateTriggerSkill{
  name = "poke__rende",
  anim_type = "offensive",
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player:getNextAlive(),data.card,false, fk.ReasonJustMove)
  end,
}

local tieji=fk.CreateTriggerSkill{
  name = "poke__tieji",
  anim_type = "offensive",
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player and data.card.trueName=="slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade,club,heart,diamond",
    }
    room:judge(judge)
    if judge.card.suit ~= nil then
        local suits = {}
        table.insert(suits, judge.card:getSuitString())
      room:askForDiscard(player, 1, 1, false, self.name, true, ".|.|"..table.concat(suits, ","), "#ex__tieji-discard:::"..judge.card:getSuitString())
    end
  end,
}

local paoxiao=fk.CreateTriggerSkill{
  name = "poke__paoxiao",
  anim_type = "offensive",
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player and data.card.trueName=="slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room

    local pattern1=".|"..tostring(data.card.number)
    local pattern2=".|.|"..tostring(data.card:getSuitString())
    local card=room:askForResponse(player, ".", pattern1..";"..pattern2..";".."slash", "#jbsuno_paoxiao-ask", true)
    if card then
      room:setBanner("@uno",{card:getSuitString(),card.number})
      room:responseCard{
        from = player.id,
        card =card,
      }
      if player:isKongcheng() then 
        player._splayer:setDied(false)
        room:setPlayerRest(player, 99)
        room:killPlayer({ who = player.id })
      end
     
  end
  end,
}

local yingzi=fk.CreateTriggerSkill{
  name = "poke__yingzi",
  anim_type = "offensive",
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(3,self.name)
    room:askForDiscard(player, 1, 1, false, self.name, true, ".","#luoyiuno-ask")
  end,
}

local dadi=fk.CreateTriggerSkill{
  name = "poke__dadi",
  anim_type = "offensive",
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "ex__zhiheng", "#exzhiheng-ask", true)
    if success then
        self.cost_data = dat
        return true
    end
end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1,self.name)
  end,
}

local keji=fk.CreateTriggerSkill{
  name = "poke__keji",
  anim_type = "offensive",
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player and player.faceup
  end,
  on_use = function(self, event, target, player, data)
    --player:turnOver()
      return true
  end,
}


local luoyi=fk.CreateTriggerSkill{
  name = "poke__luoyi",
  anim_type = "offensive",
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player 
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1,self.name)
    player.room:setPlayerMark(player, "@@ex__luoyi", 1)
  
  end,
  refresh_events = {fk.EventPhaseChanging, fk.Death},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@ex__luoyi") ~= 0 and (event == fk.Death or data.from == Player.NotActive)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@ex__luoyi", 0)
  end,
}

local luoyi_trigger = fk.CreateTriggerSkill{
  name = "#poke__luoyi_trigger",
  mute = true,
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("poke__luoyi")
      and player:getMark("@@ex__luoyi") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForDiscard(player, 1, 1, false, self.name, true, ".","#luoyiuno-ask")
  end,
}

local guanxing = fk.CreateTriggerSkill{
  name = "poke__guanxing",
  events = {fk.BeforeDrawCard},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target ~= player then return false end 
    return player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForGuanxing(player, room:getNCards(3), nil, nil)
  end,
}

local biyue=fk.CreateTriggerSkill{
  name = "poke__biyue",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and  target == player 
  end,
  on_use = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#poke__biyue-recast")
    player.room:recastCard(card , player, self.name)
  
  end,
}

local lieren = fk.CreateTriggerSkill{
  name = "poke__lieren",
  anim_type = "offensive",
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local anothers = table.filter(room:getOtherPlayers(player), function(p) return p ~= player and player:canPindian(p) end)
    local tos= room:askForChoosePlayers(player, table.map(anothers, Util.IdMapper), 1, 1, "#poke_lieren-invoke", self.name, true)
    if #tos>0 then
      local to= room:getPlayerById(tos[1])
    local pindian = player:pindian({to}, self.name)
    player:drawCards(1)
    to:drawCards(1)
    if pindian.results[to.id].winner ~= player  then
      player:drawCards(1)
    end
    if  pindian.results[to.id].winner ~=to  then
      to:drawCards(1)
    end
  end
  end,
}

T.translate("#jbsuno_paoxiao-ask","可以再打出一张花色/点数相同的杀")
T.translate("#poke__biyue-recast","可以重铸一张牌")
T.translate("#poke_lieren-invoke","选择一名角色与其拼点")
T.translate("#poke__yingzi-give","交给上家1张牌")
T.translate("#exzhiheng-ask","弃置若干牌，摸等量的牌，若弃置所有牌，额外摸一张牌")
T.translate("#luoyiuno-ask","弃置1张牌")
wolong:addSkill(kanpo)
luxun:addSkill(qianxun)
caocao:addSkill(jianxiong)
liubei:addSkill(rende)
machao:addSkill(tieji)
zhangfei:addSkill(paoxiao)
zhouyu:addSkill(yingzi)
sunquan:addSkill(dadi)
lvmeng:addSkill(keji)
luoyi:addRelatedSkill(luoyi_trigger)
xuchu:addSkill(luoyi)
zhugeliang:addSkill(guanxing)
diaochan:addSkill(biyue)
zhurong:addSkill(lieren)
T.skilltranslate("poke__qianxun",{"谦逊","你可将一张点数不大于你手牌数的牌当【无中生有】打出"})
T.skilltranslate("poke__kanpo",{"看破","你的手牌数目为全场唯一最多时，你可以将一张黑色牌当做【无懈可击】打出"})
T.skilltranslate("poke__jianxiong",{"奸雄","每局游戏限2次。你的上家打出一张牌后，你可以获得此牌。"})
T.skilltranslate("poke__rende",{"仁德","限定技。你打出一张牌后，你可以令下家获得此牌。"})
T.skilltranslate("poke__yingzi",{"英姿","回合开始时，你可以摸3张牌，然后你可以弃置一张牌。"})
T.skilltranslate("poke__tieji",{"铁骑","你打出一张【杀】后，你可以进行判定，然后你可以弃置一张与判定牌花色相同的牌。"})
T.skilltranslate("poke__paoxiao",{"咆哮","你打出一张【杀】后，你可以再打出一张花色/点数相同的【杀】。"})
T.skilltranslate("poke__wusheng",{"武圣","你的黑桃【杀】可以当做红桃【杀】。梅花【杀】可以当做方块【杀】打出"})
T.skilltranslate("poke__dadi",{"大帝","回合开始时，你可以进行一次【制衡】，然后摸1张牌"})
T.skilltranslate("poke__luoyi",{"裸衣","回合开始时，你可以摸1张牌。若如此做，直到你下回合开始，你打出牌时，可以额外弃置一张牌"})
T.skilltranslate("poke__keji",{"克己","回合开始时，你可以跳过本回合"})
T.skilltranslate("poke__biyue",{"闭月","回合结束时，你可以重铸一张牌。"})
T.skilltranslate("poke__lieren",{"烈刃","回合开始时，你可以和一名角色拼点，然后你与其各摸1张牌，没赢的角色再摸1张牌。"})
T.skilltranslate("poke__guanxing",{"观星","你摸牌前，你可以观看牌堆顶的三张牌，"..
"将其中任意张以任意顺序置于牌堆顶，其余以任意顺序置于牌堆底。"})



return extension